package com.rain.example.verifyPermissions.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rain.example.verifyPermissions.mapper.UserMapper;
import com.rain.example.verifyPermissions.models.user.Menu;
import com.rain.example.verifyPermissions.models.user.User;
import com.rain.example.verifyPermissions.models.user.UserRole;
import com.rain.example.verifyPermissions.service.RoleMenuService;
import com.rain.example.verifyPermissions.service.UserRoleService;
import com.rain.example.verifyPermissions.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserRoleService userRoleService;
    @Autowired
    private RoleMenuService roleMenuService;

    @Override
    public User loadUserByUsername(String username) {
        User user = this.getOne(Wrappers.<User>lambdaQuery().eq(User::getLoginName, username), true);
        return user;
    }

    @Override
    public List<UserRole> listUserRoleByUserId(String userId) {
        List<UserRole> list = userRoleService.list(Wrappers.<UserRole>lambdaQuery().eq(UserRole::getUserId, userId));
        return list;
    }

    @Override
    public List<Menu> listMenuByUserId(String userId) {
        List<UserRole> userRoles = this.listUserRoleByUserId(userId);
        if (CollectionUtils.isEmpty(userRoles)) {
            return Collections.emptyList();
        }
        for (UserRole userRole : userRoles) {

        }
        return null;
    }
}

